<template>
	<view class="performance_measures">
		<xbd-pages-content title="工作指标">
			<template #content>
				<view class="content" :style="'minHeight:'+windowHeight+'px'">
					<leoTree :data="typeData" @node-click="nodeClick"></leoTree>
				</view>
			</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import leoTree from "@/components/leo-tree/leo-tree.vue";
	import { Performance } from '@/api/index.js';
	export default {

		data() {
			return {
				windowHeight: 0,
				showList: [],
				typeData: [
				]
			};
		},
		components: {
			leoTree
		},
		methods: {
			nodeClick(e) {
				if(!e.children.length){
					uni.$emit('chooseTree',e)
					uni.navigateBack({
						delta:1
					})
				}
				console.log('工作指标', e);
			},
				
			async getTree(){
				try{
					this.$showLoading('加载中');
					const res = await Performance.getWorkThird()
					uni.hideLoading();
					if(res.success){
						console.log(res)
						this.typeData =res.data.trees
					}else {
						uni.showToast({
								title: res.msg,
								icon: 'none',
							})
					}
					
				}catch(e){
					uni.hideLoading();
					//TODO handle the exception
				}
			},
			async getDetailTree(id){
				try{
					this.$showLoading('加载中');
					const res = await Performance.getDetailThird(id)
					uni.hideLoading();
					if(res.success){
					this.typeData =res.data.trees
					}else {
						uni.showToast({
								title: res.msg,
								icon: 'none',
							})
					}
				}catch(e){
					uni.hideLoading();
					//TODO handle the exception
				}
			}
		},
		onLoad(res) {
			
			console.log(res)
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight
					console.log(this.windowHeight);
				}
			});
			if(res.msg === '1'){
				this.getTree()
			}else{
				this.getDetailTree(res.id)
			}
		},
		onUnload() {},
	}
</script>

<style lang="scss" scoped>
	.content {
		position: relative;
		padding-right: 40rpx;
		box-sizing: border-box;


	}
</style>
